
#define S3C2440_GPBCON  0x56000010
#define S3C2440_GPBDAT  0x56000014
#define S3C2440_GPBUP   0x56000018
#define S3C2440_GPB5_OUTP (0x01 << 10)
#define S3C2440_GPB6_OUTP (0x01 << 12)
#define S3C2440_GPB7_OUTP (0x01 << 14)
#define S3C2440_GPB8_OUTP (0x01 << 16)

#define __raw_readl(a) *(volatile unsigned int *)(a)
#define __raw_writel(v,a) *(volatile unsigned int *)(a) = (v)

void gpio_leds_init(void)
{
    unsigned int con;

    con = __raw_readl(S3C2440_GPBCON);
    con |= (S3C2440_GPB5_OUTP | S3C2440_GPB6_OUTP | S3C2440_GPB7_OUTP |
            S3C2440_GPB8_OUTP);
    __raw_writel(con, S3C2440_GPBCON);

    __raw_writel(0xff, S3C2440_GPBUP);
}

void switch_on_led(int n)
{
    unsigned int dat;
    
    /* turn off all other led, leave on only one */
    if (n < 1 || n > 4)
        return;
    
    dat = __raw_readl(S3C2440_GPBDAT);
    dat |= 0xffff;

    dat &= ~(1<<(n + 4));

    __raw_writel(dat, S3C2440_GPBDAT);
}

void entry(void)
{
    int n = 1;
    int i;

    /**
     * 4 leds controlled by 
     * GPB5 - GPB8
     */
    gpio_leds_init();

    /* turn all leds on and off by sequence */
    while (1)
    {
        // delay
        for (i = 0; i < 50000; i++);
        switch_on_led(n);

        if (n == 4)
        {
            n = 1;
            continue;
        }

        n++;
    }
}
